



package com.ukao.cashregister.pesenter;

import android.content.Context;

import com.ukao.cashregister.base.BasePresenter;
import com.ukao.cashregister.bean.StringBean;
import com.ukao.cashregister.bean.VipGroupBean;
import com.ukao.cashregister.bean.VipLeverBean;
import com.ukao.cashregister.consts.Constant;
import com.ukao.cashregister.consts.SaveParamets;
import com.ukao.cashregister.retrofit.ApiCallback;
import com.ukao.cashregister.view.VipManagerView;

import java.util.HashMap;

/**
 * Created by ukaodev on 2017/6/28.
 */

public class VipManagerPesenter extends BasePresenter<VipManagerView> {


    public VipManagerPesenter(VipManagerView view) {
        attachView(view);
    }
    /**
     *用戶分組
     */
    public void vipUserGroupData( Context mContext ) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("accessToken", SaveParamets.getToken(mContext));
        addSubscription(apiStores.vipUserGroup(Constant.createParameter(mHashMap)),
                new ApiCallback<VipGroupBean>() {
                    @Override
                    public void onSuccess(VipGroupBean model) {

                        if (model.getHttpCode()==200){

                           mvpView.loadvipGroupSucceed(  model.getData());

                        }else{

                           mvpView.loadFailure(model.getMsg());
                        }

                    }



                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }


    /**
     *用戶等級
     */
    public void vipUserLever( Context mContext  ) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("accessToken", SaveParamets.getToken(mContext));
        addSubscription(apiStores.vipUserLever( Constant.createParameter(mHashMap)),
                new ApiCallback<VipLeverBean>() {
                    @Override
                    public void onSuccess(VipLeverBean model) {
                        if (model.getHttpCode()==200){
                                 VipLeverBean.ListBean item=new VipLeverBean.ListBean();
                                 item.setName("所有等级");
                                 item.setId("");
                                 model.getData().getList().add(0,item);
                                mvpView.loadvipLeverSucceed( model.getData().getList());




                        }else{

                            mvpView.loadFailure(model.getMsg());
                        }

                    }


                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }

    /**
     *新建分组
     */
    public void buildGrouping( Context mContext, final String  name ) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("name",name);
        mHashMap.put("accessToken", SaveParamets.getToken(mContext));
        addSubscription(apiStores.buildGrouping(Constant.createParameter(mHashMap)),
                new ApiCallback<StringBean>() {
                    @Override
                    public void onSuccess(StringBean model) {

                        if (model.getHttpCode()==200){
                            VipGroupBean  mitem=new VipGroupBean();
                            mitem.setName(name);
                             mitem.setId(model.getData() );
                            mvpView.buildGroupingSucceed(mitem);

                        }else{

                            mvpView.loadFailure(model.getMsg());
                        }

                    }



                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }


    /**
     *获取全部分组与默认分组
     */
    public void allSserGroup( Context mContext ) {
        mvpView.showLoading();
        HashMap mHashMap=new HashMap<String,String>();
        mHashMap.put("accessToken", SaveParamets.getToken(mContext));
        addSubscription(apiStores.alldefauldGroup(Constant.createParameter(mHashMap)),
                new ApiCallback<VipGroupBean>() {
                    public void onSuccess(VipGroupBean model) {

                        if (model.getHttpCode()==200){

                            mvpView.loadAllSserGroupSucceed(model.getData());

                        }else{

                            mvpView.loadFailure(model.getMsg());
                        }

                    }



                    @Override
                    public void onFinish() {
                        mvpView.hideLoading();
                    }

                });
    }







}
